/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package com.kingdee.eas.fdc.propertymgmt.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.org.SaleOrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.fdc.basedata.FDCBillStateEnum;
import com.kingdee.eas.fdc.basedata.FDCHelper;
import com.kingdee.eas.fdc.basedata.FDCSQLBuilder;
import com.kingdee.eas.fdc.crm.basedata.BuildingCollection;
import com.kingdee.eas.fdc.crm.basedata.BuildingInfo;
import com.kingdee.eas.fdc.crm.basedata.BuildingUnitCollection;
import com.kingdee.eas.fdc.crm.basedata.BuildingUnitInfo;
import com.kingdee.eas.fdc.crm.basedata.MoneyDefineInfo;
import com.kingdee.eas.fdc.crm.basedata.RoomCollection;
import com.kingdee.eas.fdc.crm.basedata.RoomInfo;
import com.kingdee.eas.fdc.crm.basedata.SellProjectInfo;
import com.kingdee.eas.fdc.propertymgmt.IMeterReadingBill;
import com.kingdee.eas.fdc.propertymgmt.IMeterReadingBillEntry;
import com.kingdee.eas.fdc.propertymgmt.IPPMMeasureAR;
import com.kingdee.eas.fdc.propertymgmt.IPublicMeter;
import com.kingdee.eas.fdc.propertymgmt.IRoomCharge;
import com.kingdee.eas.fdc.propertymgmt.IRoomMeter;
import com.kingdee.eas.fdc.propertymgmt.MeterReadingBillEntryCollection;
import com.kingdee.eas.fdc.propertymgmt.MeterReadingBillEntryFactory;
import com.kingdee.eas.fdc.propertymgmt.MeterReadingBillEntryInfo;
import com.kingdee.eas.fdc.propertymgmt.MeterReadingBillFactory;
import com.kingdee.eas.fdc.propertymgmt.MeterReadingBillInfo;
import com.kingdee.eas.fdc.propertymgmt.MeterReadingBillStatus;
import com.kingdee.eas.fdc.propertymgmt.MeterSortInfo;
import com.kingdee.eas.fdc.propertymgmt.MeterSpecInfo;
import com.kingdee.eas.fdc.propertymgmt.PPMARSource;
import com.kingdee.eas.fdc.propertymgmt.PPMMeasureARFactory;
import com.kingdee.eas.fdc.propertymgmt.PPMMeasureARInfo;
import com.kingdee.eas.fdc.propertymgmt.PublicMeterCollection;
import com.kingdee.eas.fdc.propertymgmt.PublicMeterFactory;
import com.kingdee.eas.fdc.propertymgmt.PublicMeterInfo;
import com.kingdee.eas.fdc.propertymgmt.RoomChargeCollection;
import com.kingdee.eas.fdc.propertymgmt.RoomChargeFactory;
import com.kingdee.eas.fdc.propertymgmt.RoomChargeInfo;
import com.kingdee.eas.fdc.propertymgmt.RoomMeterCollection;
import com.kingdee.eas.fdc.propertymgmt.RoomMeterFactory;
import com.kingdee.eas.fdc.propertymgmt.RoomMeterInfo;
import com.kingdee.eas.fdc.sellhouse.FDCCustomerInfo;
import com.kingdee.eas.fdc.sellhouse.SubareaInfo;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.NumericExceptionSubItem;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;

// Referenced classes of package com.kingdee.eas.fdc.propertymgmt.app:
//            AbstractMeterReadingBillControllerBean

public class MeterReadingBillControllerBean extends AbstractMeterReadingBillControllerBean
{

    public MeterReadingBillControllerBean()
    {
    }

    protected void _checkRemove(Context ctx, IObjectValue vo)
        throws BOSException, EASBizException
    {
        if(vo == null)
            return;
        MeterReadingBillInfo mrBill = (MeterReadingBillInfo)vo;
        boolean isPublicMeter = mrBill.isIsPublicMeter();
        MeterReadingBillEntryCollection mrBillEntryCol = mrBill.getEntry();
        Set setRoomMeterID = new HashSet();
        Set setPublicMeterID = new HashSet();
        RoomMeterCollection roomMeterCol = null;
        PublicMeterCollection publicMeterCol = null;
        MeterReadingBillEntryInfo entryInfo = null;
        if(!isPublicMeter)
        {
            for(int i = 0; i < mrBillEntryCol.size(); i++)
            {
                entryInfo = mrBillEntryCol.get(i);
                setRoomMeterID.add(entryInfo.getRoommeter().getId());
            }

            roomMeterCol = getRoomMeterColl(ctx, setRoomMeterID);
        } else
        {
            for(int i = 0; i < mrBillEntryCol.size(); i++)
            {
                entryInfo = mrBillEntryCol.get(i);
                setPublicMeterID.add(entryInfo.getRoommeter().getId());
            }

            publicMeterCol = getPublicMeterColl(ctx, setRoomMeterID);
        }
        BigDecimal curReading = FDCHelper.ZERO;
        Date curReadingDate = null;
        RoomMeterInfo rmInfo = null;
        BigDecimal initReading = FDCHelper.ZERO;
        Date readingDate = null;
        Set setUpdateIDs = new HashSet();
        for(int i = 0; i < mrBillEntryCol.size(); i++)
        {
            entryInfo = mrBillEntryCol.get(i);
            curReading = entryInfo.getCurReading();
            curReadingDate = entryInfo.getCurReadingDate();
            if(curReadingDate != null)
                if(curReading != null);
        }

        if(setUpdateIDs != null)
            if(setUpdateIDs.size() <= 0);
    }

    protected MeterReadingBillEntryInfo getUpdateEntryInfo(PublicMeterCollection publicMeterCol, RoomMeterCollection roomMeterCol, MeterReadingBillEntryInfo entryInfo, boolean isPublicMeter)
        throws EASBizException
    {
        if(!isPublicMeter)
        {
            for(int j = 0; j < roomMeterCol.size(); j++)
            {
                RoomMeterInfo rmInfo = roomMeterCol.get(j);
                if(!FDCHelper.isEmpty(rmInfo.getMeterReadingBillEntryId()) && String.valueOf(entryInfo.getMeterId()).equals(String.valueOf(rmInfo.getId())))
                    if(!String.valueOf(entryInfo.getId()).equals(String.valueOf(rmInfo.getMeterReadingBillEntryId())))
                        throw new EASBizException(new NumericExceptionSubItem("101", "\u540E\u7EED\u6709\u6284\u8868\u8BB0\u5F55\uFF0C\u8BF7\u5148\u5220\u9664\u540E\u7EED\u6284\u8868\u8BB0\u5F55\uFF01"));
                    else
                        return entryInfo;
            }

            return null;
        }
        for(int j = 0; j < publicMeterCol.size(); j++)
        {
            PublicMeterInfo pmInfo = publicMeterCol.get(j);
            if(!FDCHelper.isEmpty(pmInfo.getMeterReadingBillEntryId()) && String.valueOf(entryInfo.getMeterId()).equals(String.valueOf(pmInfo.getId())))
                if(!String.valueOf(entryInfo.getId()).equals(String.valueOf(pmInfo.getMeterReadingBillEntryId())))
                    throw new EASBizException(new NumericExceptionSubItem("101", "\u540E\u7EED\u6709\u6284\u8868\u8BB0\u5F55\uFF0C\u8BF7\u5148\u5220\u9664\u540E\u7EED\u6284\u8868\u8BB0\u5F55\uFF01"));
                else
                    return entryInfo;
        }

        return null;
    }

    private PublicMeterCollection getPublicMeterColl(Context ctx, Set setRoomMeterID)
        throws BOSException
    {
        FilterInfo filterInfo = new FilterInfo();
        SelectorItemCollection sic = new SelectorItemCollection();
        filterInfo.getFilterItems().add(new FilterItemInfo("id", setRoomMeterID, CompareType.INCLUDE));
        EntityViewInfo evi = new EntityViewInfo();
        evi.setFilter(filterInfo);
        evi.setSelector(sic);
        sic.add(new SelectorItemInfo("*"));
        return PublicMeterFactory.getLocalInstance(ctx).getPublicMeterCollection(evi);
    }

    private RoomMeterCollection getRoomMeterColl(Context ctx, Set set)
        throws BOSException
    {
        FilterInfo filterInfo = new FilterInfo();
        SelectorItemCollection sic = new SelectorItemCollection();
        filterInfo.getFilterItems().add(new FilterItemInfo("id", set, CompareType.INCLUDE));
        EntityViewInfo evi = new EntityViewInfo();
        evi.setFilter(filterInfo);
        evi.setSelector(sic);
        sic.add(new SelectorItemInfo("*"));
        return RoomMeterFactory.getLocalInstance(ctx).getRoomMeterCollection(evi);
    }

    protected void _delete(Context ctx, IObjectPK pk)
        throws BOSException, EASBizException
    {
        MeterReadingBillInfo vo = getMeterReadingBillInfo(ctx, pk);
        super._delete(ctx, pk);
    }

    protected IObjectCollection _batchAdd(Context ctx, SellProjectInfo sellProjectInfo, MoneyDefineInfo chargeItemInfo, BuildingCollection buidlings, Date endDate, boolean isOverride)
        throws BOSException, EASBizException
    {
        if(sellProjectInfo == null || chargeItemInfo == null)
            return null;
        RoomChargeCollection rcc = fineRoomChargs(ctx, sellProjectInfo, chargeItemInfo, buidlings);
        if(rcc == null || rcc.isEmpty())
            return null;
        MeterReadingBillEntryCollection entrys = new MeterReadingBillEntryCollection();
        for(Iterator it = rcc.iterator(); it.hasNext();)
        {
            RoomChargeInfo roomChargeInfo = (RoomChargeInfo)it.next();
            RoomMeterCollection rmc = findRoomMeters(ctx, roomChargeInfo.getRoom(), chargeItemInfo);
            if(rmc != null && !rmc.isEmpty())
            {
                Iterator itMeters = rmc.iterator();
                while(itMeters.hasNext()) 
                {
                    RoomMeterInfo roomMeterInfo = (RoomMeterInfo)itMeters.next();
                    Object lastReadings[] = findLastReadings(ctx, roomChargeInfo.getRoom(), roomChargeInfo.getCustomer(), chargeItemInfo, roomMeterInfo);
                    if(lastReadings != null && lastReadings.length != 0)
                    {
                        MeterReadingBillEntryInfo entryInfo = new MeterReadingBillEntryInfo();
                        entryInfo.setBillStatus(MeterReadingBillStatus.UNLEASED);
                        entryInfo.setCustomer(roomChargeInfo.getCustomer());
                        entryInfo.setLastReading((BigDecimal)lastReadings[0]);
                        entryInfo.setLastReadingDate((Date)lastReadings[1]);
                        entryInfo.setRoom(roomChargeInfo.getRoom());
                        entryInfo.setRoommeter(roomMeterInfo);
                        entryInfo.setCurReadingDate(endDate);
                        Date feeStartDate = roomChargeInfo.getStartFeeDate((Date)lastReadings[2]);
                        Date feeEndDate = roomChargeInfo.getEndFeeDate(feeStartDate);
                        if(feeEndDate.compareTo(endDate) <= 0)
                            entrys.add(entryInfo);
                    }
                }
            }
        }

        return entrys != null && !entrys.isEmpty() ? entrys : null;
    }

    private RoomChargeCollection fineRoomChargs(Context ctx, SellProjectInfo sellProjectInfo, MoneyDefineInfo chargeItemInfo, BuildingCollection buidlings)
        throws BOSException, EASBizException
    {
        IRoomCharge irc = RoomChargeFactory.getLocalInstance(ctx);
        FilterInfo roomChargeFilter = new FilterInfo();
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("sellproject.id", sellProjectInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("chargeItem.id", chargeItemInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("isEnabled", Boolean.valueOf(true), CompareType.EQUALS));
        Set idSet = new HashSet();
        for(int i = 0; i < buidlings.size(); i++)
            idSet.add(buidlings.get(i).getId().toString());

        roomChargeFilter.getFilterItems().add(new FilterItemInfo("room.building.id", idSet, CompareType.INCLUDE));
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add(new SelectorItemInfo("*"));
        sic.add(new SelectorItemInfo("chargeStandard.*"));
        sic.add(new SelectorItemInfo("room.id"));
        sic.add(new SelectorItemInfo("room.name"));
        sic.add(new SelectorItemInfo("room.number"));
        sic.add(new SelectorItemInfo("room.displayName"));
        sic.add(new SelectorItemInfo("customer.id"));
        sic.add(new SelectorItemInfo("customer.name"));
        sic.add(new SelectorItemInfo("customer.number"));
        EntityViewInfo evi = new EntityViewInfo();
        evi.setFilter(roomChargeFilter);
        evi.setSelector(sic);
        return irc.getRoomChargeCollection(evi);
    }

    private RoomMeterCollection findRoomMeters(Context ctx, RoomInfo roomInfo, MoneyDefineInfo chargeItemInfo)
        throws BOSException, EASBizException
    {
        if(roomInfo == null || chargeItemInfo == null)
        {
            return null;
        } else
        {
            IRoomMeter irm = RoomMeterFactory.getLocalInstance(ctx);
            FilterInfo roomChargeFilter = new FilterInfo();
            roomChargeFilter.getFilterItems().add(new FilterItemInfo("room.id", roomInfo.getId(), CompareType.EQUALS));
            roomChargeFilter.getFilterItems().add(new FilterItemInfo("meterspec.meterSort.chargeItem.id", chargeItemInfo.getId(), CompareType.EQUALS));
            roomChargeFilter.getFilterItems().add(new FilterItemInfo("isEnabled", Boolean.valueOf(true), CompareType.EQUALS));
            SelectorItemCollection sic = new SelectorItemCollection();
            sic.add(new SelectorItemInfo("*"));
            sic.add(new SelectorItemInfo("meterspec.*"));
            EntityViewInfo evi = new EntityViewInfo();
            evi.setFilter(roomChargeFilter);
            evi.setSelector(sic);
            return irm.getRoomMeterCollection(evi);
        }
    }

    private Object[] findLastReadings(Context ctx, RoomInfo roomInfo, FDCCustomerInfo customerInfo, MoneyDefineInfo chargeItemInfo, RoomMeterInfo roomMeterInfo)
        throws BOSException, EASBizException
    {
        IPPMMeasureAR ipmar = PPMMeasureARFactory.getLocalInstance(ctx);
        return ipmar.getLastMeterInfo(roomInfo, customerInfo, chargeItemInfo, roomMeterInfo, null);
    }

    protected boolean _transfer(Context ctx, IObjectPK pk)
        throws BOSException, EASBizException
    {
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add(new SelectorItemInfo("*"));
        sic.add(new SelectorItemInfo("chargeItem.*"));
        sic.add(new SelectorItemInfo("Entry.*"));
        sic.add(new SelectorItemInfo("Entry.roommeter.*"));
        sic.add(new SelectorItemInfo("Entry.roommeter.meterspec.*"));
        MeterReadingBillInfo vo = getMeterReadingBillInfo(ctx, pk, sic);
        if(vo == null || vo.getChargeItem() == null || vo.getEntry() == null || vo.getEntry().isEmpty() || vo.getBillStatus().equals(MeterReadingBillStatus.TRANSFER))
            return false;
        Iterator it = vo.getEntry().iterator();
        boolean flag = true;
        while(it.hasNext()) 
        {
            MeterReadingBillEntryInfo lineVO = (MeterReadingBillEntryInfo)it.next();
            if(_createPPMAR(ctx, vo, lineVO))
            {
                SelectorItemCollection sicUpdate = new SelectorItemCollection();
                sicUpdate.add(new SelectorItemInfo("billStatus"));
                lineVO.setBillStatus(MeterReadingBillStatus.TRANSFER);
                IMeterReadingBillEntry ime = MeterReadingBillEntryFactory.getLocalInstance(ctx);
                ime.updatePartial(lineVO, sicUpdate);
            } else
            {
                flag = false;
            }
        }
        if(flag)
        {
            SelectorItemCollection sicUpdate = new SelectorItemCollection();
            sicUpdate.add(new SelectorItemInfo("billStatus"));
            vo.setBillStatus(MeterReadingBillStatus.TRANSFER);
            updatePartial(ctx, vo, sicUpdate);
        }
        return true;
    }

    private boolean _createPPMAR(Context ctx, MeterReadingBillInfo vo, MeterReadingBillEntryInfo lineVO)
        throws BOSException, EASBizException
    {
        if(vo == null || lineVO == null || lineVO.getRoom() == null || lineVO.getCustomer() == null || vo.getChargeItem() == null || lineVO.getRoommeter() == null || lineVO.getRoommeter().getMeterspec() == null)
            return false;
        if(lineVO.getFeeQuantity() == null || lineVO.getFeeQuantity().compareTo(new BigDecimal(0.0D)) == 0)
            return false;
        if(lineVO.getBillStatus().equals(MeterReadingBillStatus.TRANSFER))
            return true;
        RoomChargeInfo roomChargeInfo = _findRoomChargeInfo(ctx, lineVO.getRoom(), lineVO.getCustomer(), vo.getChargeItem());
        if(roomChargeInfo == null)
            return false;
        PPMMeasureARInfo arInfo = new PPMMeasureARInfo();
        arInfo.setAcSource(PPMARSource.SYSTEM);
        arInfo.setChargeItem(vo.getChargeItem());
        arInfo.setChargeStandard(roomChargeInfo.getChargeStandard());
        arInfo.setCustomer(lineVO.getCustomer());
        arInfo.setRoomMeter(lineVO.getRoommeter());
        arInfo.setLastMeasureDate(lineVO.getLastReadingDate());
        arInfo.setLastReading(lineVO.getLastReading());
        arInfo.setCurReadingDate(lineVO.getCurReadingDate());
        arInfo.setCurrentReading(lineVO.getCurReading());
        arInfo.setStartFeeDate(roomChargeInfo.getStartFeeDate(lineVO.getLastReadingDate()));
        arInfo.setEndFeeDate(lineVO.getCurReadingDate());
        arInfo.setArDate(roomChargeInfo.getARDate(arInfo.getStartFeeDate(), arInfo.getEndFeeDate()));
        arInfo.setRoom(lineVO.getRoom());
        arInfo.setWastage(lineVO.getFeeQuantity());
        arInfo.setUnitPrice(roomChargeInfo.getUnitPrice());
        arInfo.setPriceFactor(roomChargeInfo.getPriceFactor());
        arInfo.setPricePeriod(roomChargeInfo.getPricePeriod());
        arInfo.setFeeQuantity(roomChargeInfo.getFeeQuantity());
        arInfo.setArAmout(arInfo.getARAmount(arInfo.getUnitPrice(), arInfo.getWastage()));
        arInfo.setBizDate(new Date(System.currentTimeMillis()));
        arInfo.setDerateAmount(new BigDecimal(0.0D));
        arInfo.setDescription("\u6284\u8868\u5355\u53F7:" + vo.getNumber());
        arInfo.setHandler(vo.getHandler());
        arInfo.setPayedAmount(new BigDecimal(0.0D));
        arInfo.setState(FDCBillStateEnum.AUDITTED);
        arInfo.setSellproject(vo.getSellproject());
        if(arInfo.getArAmout() == null || arInfo.getArAmout().compareTo(new BigDecimal("0.0")) == 0)
        {
            return false;
        } else
        {
            IPPMMeasureAR ipma = PPMMeasureARFactory.getLocalInstance(ctx);
            ipma.addnew(arInfo);
            return true;
        }
    }

    private RoomChargeInfo _findRoomChargeInfo(Context ctx, RoomInfo roomInfo, FDCCustomerInfo customerInfo, MoneyDefineInfo chrageItemInfo)
        throws BOSException, EASBizException
    {
        IRoomCharge irc = RoomChargeFactory.getLocalInstance(ctx);
        FilterInfo roomChargeFilter = new FilterInfo();
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("room.id", roomInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("customer.id", customerInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("chargeItem.id", chrageItemInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("isEnabled", Boolean.valueOf(true), CompareType.EQUALS));
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add(new SelectorItemInfo("*"));
        sic.add(new SelectorItemInfo("chargeStandard.*"));
        EntityViewInfo evi = new EntityViewInfo();
        evi.setFilter(roomChargeFilter);
        evi.setSelector(sic);
        RoomChargeCollection rcc = irc.getRoomChargeCollection(evi);
        return rcc != null && !rcc.isEmpty() ? rcc.get(0) : null;
    }

    protected IObjectCollection _batchAddByUnit(Context ctx, SellProjectInfo sellProject, MoneyDefineInfo chargeItemInfo, BuildingUnitCollection buildingUnits, Date endDate, boolean isOverride)
        throws BOSException, EASBizException
    {
        if(sellProject == null || chargeItemInfo == null)
            return null;
        RoomChargeCollection rcc = findRoomChargs(ctx, sellProject, chargeItemInfo, buildingUnits);
        if(rcc == null || rcc.isEmpty())
            return null;
        MeterReadingBillEntryCollection entrys = new MeterReadingBillEntryCollection();
        for(Iterator it = rcc.iterator(); it.hasNext();)
        {
            RoomChargeInfo roomChargeInfo = (RoomChargeInfo)it.next();
            RoomMeterCollection rmc = findRoomMeters(ctx, roomChargeInfo.getRoom(), chargeItemInfo);
            if(rmc != null && !rmc.isEmpty())
            {
                Iterator itMeters = rmc.iterator();
                while(itMeters.hasNext()) 
                {
                    RoomMeterInfo roomMeterInfo = (RoomMeterInfo)itMeters.next();
                    Object lastReadings[] = findLastReadings(ctx, roomChargeInfo.getRoom(), roomChargeInfo.getCustomer(), chargeItemInfo, roomMeterInfo);
                    if(lastReadings != null && lastReadings.length != 0)
                    {
                        MeterReadingBillEntryInfo entryInfo = new MeterReadingBillEntryInfo();
                        entryInfo.setBillStatus(MeterReadingBillStatus.UNLEASED);
                        entryInfo.setCustomer(roomChargeInfo.getCustomer());
                        entryInfo.setLastReading((BigDecimal)lastReadings[0]);
                        entryInfo.setLastReadingDate((Date)lastReadings[1]);
                        entryInfo.setRoom(roomChargeInfo.getRoom());
                        entryInfo.setRoommeter(roomMeterInfo);
                        entryInfo.setCurReadingDate(endDate);
                        Date feeStartDate = roomChargeInfo.getStartFeeDate((Date)lastReadings[2]);
                        Date feeEndDate = roomChargeInfo.getEndFeeDate(feeStartDate);
                        if(feeEndDate.compareTo(endDate) <= 0)
                            entrys.add(entryInfo);
                    }
                }
            }
        }

        return entrys != null && !entrys.isEmpty() ? entrys : null;
    }

    private RoomChargeCollection findRoomChargs(Context ctx, SellProjectInfo sellProject, MoneyDefineInfo chargeInfo, BuildingUnitCollection units)
        throws BOSException
    {
        IRoomCharge irc = RoomChargeFactory.getLocalInstance(ctx);
        FilterInfo roomChargeFilter = new FilterInfo();
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("sellproject.id", sellProject.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("chargeItem.id", chargeInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("isEnabled", Boolean.valueOf(true), CompareType.EQUALS));
        Set idSet = new HashSet();
        for(int i = 0; i < units.size(); i++)
            idSet.add(units.get(i).getId().toString());

        roomChargeFilter.getFilterItems().add(new FilterItemInfo("room.buildUnit.id", idSet, CompareType.INCLUDE));
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add(new SelectorItemInfo("*"));
        sic.add(new SelectorItemInfo("chargeStandard.*"));
        sic.add(new SelectorItemInfo("room.*"));
        sic.add(new SelectorItemInfo("customer.*"));
        EntityViewInfo evi = new EntityViewInfo();
        evi.setFilter(roomChargeFilter);
        evi.setSelector(sic);
        return irc.getRoomChargeCollection(evi);
    }

    protected IObjectCollection _batchAddByRoom(Context ctx, SellProjectInfo sellProject, MoneyDefineInfo chargeItemInfo, RoomCollection roomInfos, Date endDate, boolean isOverride)
        throws BOSException, EASBizException
    {
        if(sellProject == null || chargeItemInfo == null)
            return null;
        RoomChargeCollection rcc = findRoomChargs(ctx, sellProject, chargeItemInfo, roomInfos);
        if(rcc == null || rcc.isEmpty())
            return null;
        MeterReadingBillEntryCollection entrys = new MeterReadingBillEntryCollection();
        for(Iterator it = rcc.iterator(); it.hasNext();)
        {
            RoomChargeInfo roomChargeInfo = (RoomChargeInfo)it.next();
            RoomMeterCollection rmc = findRoomMeters(ctx, roomChargeInfo.getRoom(), chargeItemInfo);
            if(rmc != null && !rmc.isEmpty())
            {
                Iterator itMeters = rmc.iterator();
                while(itMeters.hasNext()) 
                {
                    RoomMeterInfo roomMeterInfo = (RoomMeterInfo)itMeters.next();
                    Object lastReadings[] = findLastReadings(ctx, roomChargeInfo.getRoom(), roomChargeInfo.getCustomer(), chargeItemInfo, roomMeterInfo);
                    if(lastReadings != null && lastReadings.length != 0)
                    {
                        MeterReadingBillEntryInfo entryInfo = new MeterReadingBillEntryInfo();
                        entryInfo.setBillStatus(MeterReadingBillStatus.UNLEASED);
                        entryInfo.setCustomer(roomChargeInfo.getCustomer());
                        entryInfo.setLastReading((BigDecimal)lastReadings[0]);
                        entryInfo.setLastReadingDate((Date)lastReadings[1]);
                        entryInfo.setRoom(roomChargeInfo.getRoom());
                        entryInfo.setRoommeter(roomMeterInfo);
                        entryInfo.setCurReadingDate(endDate);
                        Date feeStartDate = roomChargeInfo.getStartFeeDate((Date)lastReadings[2]);
                        Date feeEndDate = roomChargeInfo.getEndFeeDate(feeStartDate);
                        if(feeEndDate.compareTo(endDate) <= 0)
                            entrys.add(entryInfo);
                    }
                }
            }
        }

        return entrys != null && !entrys.isEmpty() ? entrys : null;
    }

    private RoomChargeCollection findRoomChargs(Context ctx, SellProjectInfo sellProjectInfo, MoneyDefineInfo chargeInfo, RoomCollection roomInfos)
        throws BOSException
    {
        IRoomCharge irc = RoomChargeFactory.getLocalInstance(ctx);
        FilterInfo roomChargeFilter = new FilterInfo();
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("sellproject.id", sellProjectInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("chargeItem.id", chargeInfo.getId(), CompareType.EQUALS));
        roomChargeFilter.getFilterItems().add(new FilterItemInfo("isEnabled", Boolean.valueOf(true), CompareType.EQUALS));
        Set idSet = new HashSet();
        for(int i = 0; i < roomInfos.size(); i++)
            idSet.add(roomInfos.get(i).getId().toString());

        roomChargeFilter.getFilterItems().add(new FilterItemInfo("room.id", idSet, CompareType.INCLUDE));
        SelectorItemCollection sic = new SelectorItemCollection();
        sic.add(new SelectorItemInfo("*"));
        sic.add(new SelectorItemInfo("chargeStandard.*"));
        sic.add(new SelectorItemInfo("room.*"));
        sic.add(new SelectorItemInfo("customer.*"));
        EntityViewInfo evi = new EntityViewInfo();
        evi.setFilter(roomChargeFilter);
        evi.setSelector(sic);
        return irc.getRoomChargeCollection(evi);
    }

    protected IObjectCollection _batchGenerator(Context ctx, SellProjectInfo sellProjectInfo, BuildingInfo building, BuildingUnitInfo buildUnit, MeterSortInfo meterSortInfo, MeterSpecInfo meterSpecInfo, boolean isPublicMeter, 
            Map pareMap)
        throws BOSException
    {
        MeterReadingBillEntryCollection entrys = new MeterReadingBillEntryCollection();
        if(pareMap == null || pareMap.get("saleOrg") == null)
            return entrys;
        if(sellProjectInfo == null || meterSortInfo == null)
            return entrys;
        SaleOrgUnitInfo saleOrg = (SaleOrgUnitInfo)pareMap.get("saleOrg");
        SubareaInfo subareaInfo = (SubareaInfo)pareMap.get("subareaInfo");
        Map readEntryMap = new HashMap();
        String meterIdStr = "";
        com.kingdee.eas.basedata.person.PersonInfo currPersonInfo = ContextUtil.getCurrentUserInfo(ctx).getPerson();
        if(isPublicMeter)
        {
            StringBuffer kSQLPublicMeter = new StringBuffer("select sellproject.subarea.id, name,number,address,meterSpec.name,meterSpec.number,meterSpec.times,meterTimes,maxReading,initialReading,readingDate,wasteRate ");
            kSQLPublicMeter.append(" where  isEnabled = 1 ");
            kSQLPublicMeter.append(" and isNeedReading = 0 ");
            kSQLPublicMeter.append(" and meterSort.id='");
            kSQLPublicMeter.append(meterSortInfo.getId());
            kSQLPublicMeter.append("'");
            if(meterSpecInfo != null && meterSpecInfo.getId() != null)
            {
                kSQLPublicMeter.append(" and meterSpec.id='");
                kSQLPublicMeter.append(meterSpecInfo.getId());
                kSQLPublicMeter.append("'");
            }
            kSQLPublicMeter.append(" and orgUnit.id='");
            kSQLPublicMeter.append(saleOrg.getId());
            kSQLPublicMeter.append("'");
            PublicMeterCollection pubMeterColl = PublicMeterFactory.getLocalInstance(ctx).getPublicMeterCollection(kSQLPublicMeter.toString());
            for(int i = 0; i < pubMeterColl.size(); i++)
            {
                PublicMeterInfo pubMeterInfo = pubMeterColl.get(i);
                MeterReadingBillEntryInfo meterEntryInfo = new MeterReadingBillEntryInfo();
                meterEntryInfo.setIsChangeMeter(false);
                meterEntryInfo.setIsTurnAround(false);
                meterEntryInfo.setCurReadingDate(new Date());
                meterEntryInfo.setReadingPerson(currPersonInfo);
                meterEntryInfo.setPublicMeter(pubMeterInfo);
                meterEntryInfo.setMeterId(pubMeterInfo.getId().toString());
                meterEntryInfo.put("location", pubMeterInfo.getAddress());
                meterEntryInfo.setLastReadingDate(pubMeterInfo.getReadingDate());
                meterEntryInfo.setLastReading(pubMeterInfo.getInitialReading());
                FDCSQLBuilder meterReading = new FDCSQLBuilder();
                meterReading.appendSql("select FFeeQuantity from T_PPM_MeterReadingBillEntry where ");
                meterReading.appendParam("FPublicMeterID", pubMeterInfo.getId().toString());
                meterReading.appendSql(" and ");
                if(pubMeterInfo.getInitialReading() == null)
                    meterReading.appendParam("FCurReading", FDCHelper.ZERO);
                else
                    meterReading.appendParam("FCurReading", pubMeterInfo.getInitialReading());
                IRowSet row = meterReading.executeQuery(ctx);
                try
                {
                    if(row.next())
                        meterEntryInfo.setLastQuantity(row.getBigDecimal("FFeeQuantity"));
                }
                catch(SQLException e1)
                {
                    e1.printStackTrace();
                    throw new BOSException("\u6267\u884Csql\u67E5\u8BE2\u5931\u8D25\uFF01\uFF01\uFF01");
                }
                meterEntryInfo.setNewWasteRate(pubMeterInfo.getWasteRate());
                readEntryMap.put(pubMeterInfo.getId().toString(), meterEntryInfo);
                entrys.add(meterEntryInfo);
                meterIdStr = meterIdStr + (i != 0 ? "," : "") + "'" + pubMeterInfo.getId().toString() + "'";
            }

        } else
        {
            StringBuffer kSqlRoomMeter = new StringBuffer("");
            kSqlRoomMeter.append("select name,number,location,room.name,room.number,room.roomPropNo,meterSpec.name,meterSpec.number,meterSpec.times,meterTimes,maxReading,initReading,readingDate,wasteRate, ");
            kSqlRoomMeter.append("room.building.name,room.building.number,room.buildUnit.name,room.buildUnit.number ");
            kSqlRoomMeter.append(" where  isEnabled = 1  ");
            kSqlRoomMeter.append(" and meterSort.id='");
            kSqlRoomMeter.append(meterSortInfo.getId());
            kSqlRoomMeter.append("' ");
            if(meterSpecInfo != null)
            {
                kSqlRoomMeter.append(" and meterSpec.id='");
                kSqlRoomMeter.append(meterSpecInfo.getId());
                kSqlRoomMeter.append("' ");
            }
            kSqlRoomMeter.append("and sellproject.id='");
            kSqlRoomMeter.append(sellProjectInfo.getId());
            kSqlRoomMeter.append("' ");
            if(building != null)
            {
                kSqlRoomMeter.append(" and room.building.id = '");
                kSqlRoomMeter.append(building.getId());
                kSqlRoomMeter.append("' ");
            }
            if(null != subareaInfo) {
            	 kSqlRoomMeter.append(" and room.building.subarea.id = '");
                 kSqlRoomMeter.append(subareaInfo.getId());
                 kSqlRoomMeter.append("' ");
            }
            if(buildUnit != null)
            {
                kSqlRoomMeter.append(" and room.buildUnit.id = '");
                kSqlRoomMeter.append(buildUnit.getId());
                kSqlRoomMeter.append("'");
            }
            kSqlRoomMeter.append(" order by room.building.number,room.buildUnit.number,room.number asc");
            RoomMeterCollection roomMeterColl = RoomMeterFactory.getLocalInstance(ctx).getRoomMeterCollection(kSqlRoomMeter.toString());
            for(int i = 0; i < roomMeterColl.size(); i++)
            {
                RoomMeterInfo roomMeterInfo = roomMeterColl.get(i);
                MeterReadingBillEntryInfo meterEntryInfo = new MeterReadingBillEntryInfo();
                meterEntryInfo.setIsChangeMeter(false);
                meterEntryInfo.setIsTurnAround(false);
                meterEntryInfo.setCurReadingDate(new Date());
                meterEntryInfo.setReadingPerson(currPersonInfo);
                meterEntryInfo.setRoom(roomMeterInfo.getRoom());
                meterEntryInfo.setRoommeter(roomMeterInfo);
                meterEntryInfo.setMeterId(roomMeterInfo.getId().toString());
                meterEntryInfo.put("location", roomMeterInfo.getLocation());
                meterEntryInfo.setLastReadingDate(roomMeterInfo.getReadingDate());
                meterEntryInfo.setLastReading(roomMeterInfo.getInitReading());
                meterEntryInfo.setNewWasteRate(roomMeterInfo.getWasteRate());
                FDCSQLBuilder meterReading = new FDCSQLBuilder();
                meterReading.appendSql("select FFeeQuantity from T_PPM_MeterReadingBillEntry where ");
                meterReading.appendParam("FRoommeterID", roomMeterInfo.getId().toString());
                meterReading.appendSql(" and ");
                if(roomMeterInfo.getInitReading() == null)
                    meterReading.appendParam("FCurReading", FDCHelper.ZERO);
                else
                    meterReading.appendParam("FCurReading", roomMeterInfo.getInitReading());
                IRowSet row = meterReading.executeQuery(ctx);
                try
                {
                    if(row.next())
                        meterEntryInfo.setLastQuantity(row.getBigDecimal("FFeeQuantity"));
                }
                catch(SQLException e1)
                {
                    e1.printStackTrace();
                    throw new BOSException("\u6267\u884Csql\u67E5\u8BE2\u5931\u8D25\uFF01\uFF01\uFF01");
                }
                readEntryMap.put(roomMeterInfo.getId().toString(), meterEntryInfo);
                entrys.add(meterEntryInfo);
                meterIdStr = meterIdStr + (i != 0 ? "," : "") + "'" + roomMeterInfo.getId().toString() + "'";
            }

        }
        return entrys;
    }

    protected void _audit(Context ctx, BOSUuid billId)
        throws BOSException, EASBizException
    {
        super._audit(ctx, billId);
        FDCSQLBuilder sqlBuild = new FDCSQLBuilder(ctx);
        sqlBuild.appendSql(" select bill.FisPublicMeter,billEntry.FRoomMeterID,billEntry.FPublicMeterID, ");
        sqlBuild.appendSql(" \t\tbillEntry.FCurReading,billEntry.FCurReadingDate, billEntry.FID ");
        sqlBuild.appendSql("  from t_ppm_meterReadingbill bill  ");
        sqlBuild.appendSql("       inner join T_PPM_MeterReadingBillEntry billEntry ");
        sqlBuild.appendSql("       on  bill.fid = billEntry.fparentid  ");
        sqlBuild.appendSql("  where bill.fid ='" + String.valueOf(billId) + "' ");
        IRowSet rowSet = sqlBuild.executeQuery(ctx);
        FDCSQLBuilder sqlBuildForBatch = new FDCSQLBuilder(ctx);
        sqlBuildForBatch.setBatchType("StatementType");
        String sql = "";
        try
        {
            RoomMeterCollection roomMeterCol = null;
            PublicMeterCollection publicMeterCol = null;
            FDCSQLBuilder buildBatchMentryLastEntryID = new FDCSQLBuilder(ctx);
            buildBatchMentryLastEntryID.setBatchType("StatementType");
            String sqlEntryID = "";
            Set idSet = new HashSet();
            Map entryIDMap = new HashMap();
            boolean fisPublicMeter = true;
            for(; rowSet.next(); sqlBuildForBatch.addBatch(sql))
            {
                fisPublicMeter = rowSet.getBoolean("FisPublicMeter");
                java.sql.Date fCurReadingDate = rowSet.getDate("FCurReadingDate");
                String entryID = rowSet.getString("FID");
                Date fCurReadingDateUtil = new Date(fCurReadingDate.getTime());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String fCurReadingDateStr = sdf.format(fCurReadingDateUtil);
                BigDecimal fCurReading = rowSet.getBigDecimal("FCurReading");
                if(!fisPublicMeter)
                {
                    String fRoomMeterID = rowSet.getString("FRoomMeterID");
                    sql = " update T_PPM_RoomMeter set FMeterReadingBillEntryId='" + entryID + "', finitReading= " + fCurReading + " ,freadingDate={ts'" + fCurReadingDateStr + "'} where fid ='" + fRoomMeterID + "' ";
                    idSet.add(fRoomMeterID);
                    entryIDMap.put(fRoomMeterID, entryID);
                } else
                {
                    String fPublicMeterID = rowSet.getString("FPublicMeterID");
                    sql = " update t_ppm_publicmeter set FMeterReadingBillEntryId='" + entryID + "', finitialReading= " + fCurReading + " ,freadingDate={ts'" + fCurReadingDateStr + "'} where fid ='" + fPublicMeterID + "' ";
                    idSet.add(fPublicMeterID);
                    entryIDMap.put(fPublicMeterID, entryID);
                }
            }

            if(!fisPublicMeter)
            {
                roomMeterCol = getRoomMeterColl(ctx, idSet);
                for(int i = 0; i < roomMeterCol.size(); i++)
                {
                    RoomMeterInfo roomMeterInfo = roomMeterCol.get(i);
                    if(!FDCHelper.isEmpty(roomMeterInfo.getMeterReadingBillEntryId()))
                        sqlEntryID = " update T_PPM_MeterReadingBillEntry  set FLastMeterReadingEntryID = '" + roomMeterInfo.getMeterReadingBillEntryId() + "' where FID='" + entryIDMap.get(String.valueOf(roomMeterInfo.getId())) + "' ";
                    else
                        sqlEntryID = "";
                    try
                    {
                        if(sqlEntryID.length() > 0)
                            buildBatchMentryLastEntryID.addBatch(sqlEntryID);
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                        throw new BOSException("\u67E5\u8BE2\u5386\u53F2\u6284\u8868\u660E\u7EC6\u5931\u8D25\uFF01\uFF01\uFF01");
                    }
                }

            } else
            {
                publicMeterCol = getPublicMeterColl(ctx, idSet);
                for(int i = 0; i < publicMeterCol.size(); i++)
                {
                    PublicMeterInfo publicMeterInfo = publicMeterCol.get(i);
                    if(!FDCHelper.isEmpty(publicMeterInfo.getMeterReadingBillEntryId()))
                        sqlEntryID = " update T_PPM_MeterReadingBillEntry  set FLastMeterReadingEntryID = '" + publicMeterInfo.getMeterReadingBillEntryId() + "' where FID='" + entryIDMap.get(String.valueOf(publicMeterInfo.getId())) + "' ";
                    else
                        sqlEntryID = "";
                    try
                    {
                        if(sqlEntryID.length() > 0)
                            buildBatchMentryLastEntryID.addBatch(sqlEntryID);
                        continue;
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                    throw new BOSException("\u67E5\u8BE2\u5386\u53F2\u6284\u8868\u660E\u7EC6\u5931\u8D25\uFF01\uFF01\uFF01");
                }

            }
            buildBatchMentryLastEntryID.executeBatch();
            sqlBuildForBatch.executeBatch();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
            throw new BOSException("\u6267\u884Csql\u8BED\u53E5\u5931\u8D25\uFF01\uFF01\uFF01");
        }
    }

    protected void _unAudit(Context ctx, BOSUuid billId)
        throws BOSException, EASBizException
    {
        MeterReadingBillInfo vo = getMeterReadingBillInfo(ctx, billId);
        checkUnaudit(ctx, vo);
        super._unAudit(ctx, billId);
    }

    private MeterReadingBillInfo getMeterReadingBillInfo(Context ctx, BOSUuid billId)
        throws EASBizException, BOSException
    {
        return MeterReadingBillFactory.getLocalInstance(ctx).getMeterReadingBillInfo(" select *,Entry.*,Entry.lastMeterReadingEntry.id where id = '" + String.valueOf(billId) + "'");
    }

    protected void checkUnaudit(Context ctx, IObjectValue vo)
        throws BOSException, EASBizException
    {
        if(vo == null)
            return;
        MeterReadingBillInfo mrBill = (MeterReadingBillInfo)vo;
        boolean isPublicMeter = mrBill.isIsPublicMeter();
        MeterReadingBillEntryCollection mrBillEntryCol = mrBill.getEntry();
        Set setRoomMeterID = new HashSet();
        Set setPublicMeterID = new HashSet();
        RoomMeterCollection roomMeterCol = null;
        PublicMeterCollection publicMeterCol = null;
        MeterReadingBillEntryInfo entryInfo = null;
        if(!isPublicMeter)
        {
            for(int i = 0; i < mrBillEntryCol.size(); i++)
            {
                entryInfo = mrBillEntryCol.get(i);
                setRoomMeterID.add(entryInfo.getRoommeter().getId());
            }

            roomMeterCol = getRoomMeterColl(ctx, setRoomMeterID);
        } else
        {
            for(int i = 0; i < mrBillEntryCol.size(); i++)
            {
                entryInfo = mrBillEntryCol.get(i);
                setPublicMeterID.add(entryInfo.getPublicMeter().getId());
            }

            publicMeterCol = getPublicMeterColl(ctx, setPublicMeterID);
        }
        Map mapEntryID2EntryInfo = new HashMap();
        MeterReadingBillEntryInfo bilEntryInfo = null;
        for(int i = 0; i < mrBillEntryCol.size(); i++)
        {
            entryInfo = mrBillEntryCol.get(i);
            if(!isPublicMeter)
            {
                bilEntryInfo = getUpdateEntryInfo(null, roomMeterCol, entryInfo, isPublicMeter);
                if(bilEntryInfo != null)
                {
                    List bilEntry2PubInfoList = new ArrayList();
                    bilEntry2PubInfoList.add(new Boolean(isPublicMeter));
                    bilEntry2PubInfoList.add(bilEntryInfo);
                    mapEntryID2EntryInfo.put(String.valueOf(bilEntryInfo.getId()), bilEntry2PubInfoList);
                }
                continue;
            }
            bilEntryInfo = getUpdateEntryInfo(publicMeterCol, null, entryInfo, isPublicMeter);
            if(bilEntryInfo != null)
            {
                List bilEntry2PubInfoList = new ArrayList();
                bilEntry2PubInfoList.add(new Boolean(isPublicMeter));
                bilEntry2PubInfoList.add(bilEntryInfo);
                mapEntryID2EntryInfo.put(String.valueOf(bilEntryInfo.getId()), bilEntry2PubInfoList);
            }
        }

        Set lastMeterReadingEntryIdSet = new HashSet();
        Map notLastMeterReadingEntryMap = new HashMap();
        if(mapEntryID2EntryInfo != null && mapEntryID2EntryInfo.keySet().size() > 0)
        {
            Set entryKeySet = mapEntryID2EntryInfo.keySet();
            for(Iterator entryIt = entryKeySet.iterator(); entryIt.hasNext();)
            {
                String entryId = (String)entryIt.next();
                MeterReadingBillEntryInfo tempEntryInfo = (MeterReadingBillEntryInfo)((List)mapEntryID2EntryInfo.get(entryId)).get(1);
                if(tempEntryInfo.getLastMeterReadingEntry() != null)
                {
                    lastMeterReadingEntryIdSet.add(String.valueOf(tempEntryInfo.getLastMeterReadingEntry().getId()));
                } else
                {
                    List meterReadingInfoList = new ArrayList();
                    meterReadingInfoList.add(((List)mapEntryID2EntryInfo.get(entryId)).get(0));
                    meterReadingInfoList.add(tempEntryInfo.getLastReading());
                    meterReadingInfoList.add(tempEntryInfo.getLastReadingDate());
                    notLastMeterReadingEntryMap.put(tempEntryInfo.getMeterId(), meterReadingInfoList);
                }
            }

        }
        IRowSet rowSet = getMeterReadingEntryCollByIdSet(ctx, lastMeterReadingEntryIdSet);
        try
        {
            FDCSQLBuilder sqlBuildForRoomMeterBatch = new FDCSQLBuilder(ctx);
            FDCSQLBuilder sqlBuildForPublicMeterBatch = new FDCSQLBuilder(ctx);
            sqlBuildForRoomMeterBatch.setBatchType("StatementType");
            sqlBuildForPublicMeterBatch.setBatchType("StatementType");
            String sql = "";
            while(rowSet.next()) 
            {
                boolean fisPublicMeter = rowSet.getBoolean("FisPublicMeter");
                java.sql.Date fCurReadingDate = rowSet.getDate("FCurReadingDate");
                String entryID = rowSet.getString("FID");
                Date fCurReadingDateUtil = new Date(fCurReadingDate.getTime());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String fCurReadingDateStr = sdf.format(fCurReadingDateUtil);
                BigDecimal fCurReading = rowSet.getBigDecimal("FCurReading");
                if(!fisPublicMeter)
                {
                    String fRoomMeterID = rowSet.getString("FRoomMeterID");
                    sql = " update T_PPM_RoomMeter set FMeterReadingBillEntryId='" + entryID + "', finitReading= " + fCurReading + " ,freadingDate={ts'" + fCurReadingDateStr + "'} where fid ='" + fRoomMeterID + "' ";
                    sqlBuildForRoomMeterBatch.addBatch(sql);
                } else
                {
                    String fPublicMeterID = rowSet.getString("FPublicMeterID");
                    sql = " update t_ppm_publicmeter set FMeterReadingBillEntryId='" + entryID + "', finitialReading= " + fCurReading + " ,freadingDate={ts'" + fCurReadingDateStr + "'} where fid ='" + fPublicMeterID + "' ";
                    sqlBuildForPublicMeterBatch.addBatch(sql);
                }
            }
            if(notLastMeterReadingEntryMap != null && notLastMeterReadingEntryMap.size() > 0)
            {
                for(Iterator ite = notLastMeterReadingEntryMap.keySet().iterator(); ite.hasNext();)
                {
                    String meterId = String.valueOf(ite.next());
                    List list = (List)notLastMeterReadingEntryMap.get(meterId);
                    if(!((Boolean)list.get(0)).booleanValue())
                    {
                        sql = " update T_PPM_RoomMeter set FMeterReadingBillEntryId=null, finitReading= " + (BigDecimal)list.get(1);
                        if((Date)list.get(2) != null)
                            sql = sql + " ,freadingDate={ts'" + (Date)list.get(2) + "'} ";
                        else
                            sql = sql + " ,freadingDate=null ";
                        sql = sql + " where fid ='" + meterId + "' ";
                        sqlBuildForRoomMeterBatch.addBatch(sql);
                    } else
                    {
                        sql = " update t_ppm_publicmeter set FMeterReadingBillEntryId=null, finitialReading= " + (BigDecimal)list.get(1);
                        if((Date)list.get(2) != null)
                            sql = sql + " ,freadingDate={ts'" + (Date)list.get(2) + "'} ";
                        else
                            sql = sql + " ,freadingDate=null ";
                        sql = sql + " where fid ='" + meterId + "' ";
                        sqlBuildForPublicMeterBatch.addBatch(sql);
                    }
                }

            }
            sqlBuildForRoomMeterBatch.executeBatch();
            sqlBuildForPublicMeterBatch.executeBatch();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
            throw new BOSException("\u6267\u884Csql\u8BED\u53E5\u5931\u8D25\uFF01\uFF01\uFF01");
        }
    }

    private IRowSet getMeterReadingEntryCollByIdSet(Context ctx, Set lastMeterReadingEntryIdSet)
        throws BOSException
    {
        String idStr = setToString(lastMeterReadingEntryIdSet);
        FDCSQLBuilder sqlBuild = new FDCSQLBuilder(ctx);
        sqlBuild.appendSql(" select  bill.FisPublicMeter,billEntry.FID,billEntry.FRoomMeterID,billEntry.FPublicMeterID,billEntry.FLastMeterReadingEntryID,billEntry.FCurReading,billEntry.FCurReadingDate ");
        sqlBuild.appendSql("   from T_PPM_MeterReadingBillEntry billEntry ");
        sqlBuild.appendSql("        left join t_ppm_meterReadingbill bill on  bill.fid = billEntry.fparentid ");
        sqlBuild.appendSql("  where billEntry.fid in (" + idStr + ") ");
        IRowSet rowSet = sqlBuild.executeQuery(ctx);
        return rowSet;
    }

    private String setToString(Set lastMeterReadingEntryIdSet)
    {
        String retStr = "";
        Iterator it = lastMeterReadingEntryIdSet.iterator();
        StringBuffer id = new StringBuffer("");
        for(; it.hasNext(); id.append("'").append((String)it.next()).append("',"));
        retStr = id.toString();
        if(retStr.length() > 0)
            retStr = retStr.substring(0, retStr.length() - 1);
        if(retStr.length() == 0)
            return "'nullnull'";
        else
            return retStr;
    }

    private static final long serialVersionUID = -5769129121564644563L;
    private static Logger logger = Logger.getLogger("com.kingdee.eas.fdc.propertymgmt.app.MeterReadingBillControllerBean");

}


/*
	DECOMPILATION REPORT

	Decompiled from: D:\ay750Project\aoyuan750\lib\server\eas\fdc_propertymgmt-server.jar
	Total time: 94 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/